//
//  EJSSettingTableViewController.m
//  EnjoyShoppingStreet
//
//  Created by lifayu on 2017/12/13.
//  Copyright © 2017年 lifayu. All rights reserved.
//

#import "EJSSettingTableViewController.h"
#import "EJSAboutUsViewController.h"
#import "EJSUserInfoViewController.h"
#import "EJSManageAddressViewController.h"
#import <SDWebImageManager.h>
#import <SDImageCache.h>
@interface EJSSettingTableViewController ()

@end

@implementation EJSSettingTableViewController

+ (instancetype)viewController
{
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Mine" bundle:nil];
    return [storyBoard instantiateViewControllerWithIdentifier:@"EJSSettingTableViewController"];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // Uncomment the following line to preserve selection between presentations.
    // self.clearsSelectionOnViewWillAppear = NO;
    
    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.
    // self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [super tableView:tableView didSelectRowAtIndexPath:indexPath];
    if(indexPath.row == 0){
        EJSUserInfoViewController *aboutUsVC = [EJSUserInfoViewController viewController];
        [self.navigationController pushViewController:aboutUsVC animated:YES];
    }
    else if(indexPath.row == 1){
        EJSManageAddressViewController *aboutUsVC = [EJSManageAddressViewController viewController];
        [self.navigationController pushViewController:aboutUsVC animated:YES];
    }
    else if(indexPath.row == 2){
       MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
        [[SDImageCache sharedImageCache] clearDiskOnCompletion:^{
            [hud hideAnimated:YES];
            [[HUDHelper sharedInstance] tipMessage:@"清除成功"];
        }];
    }
    else if(indexPath.row == 3){
        EJSAboutUsViewController *aboutUsVC = [[EJSAboutUsViewController alloc] initWithNibName:@"FlyWebViewController" bundle:nil];
        [self.navigationController pushViewController:aboutUsVC animated:YES];
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 160;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UITableViewHeaderFooterView *footerView = [[UITableViewHeaderFooterView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 160)];
    footerView.contentView.backgroundColor = kWhiteColor;
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(25, 60, ScreenWidth - 50, 50);
    button.backgroundColor = AppMainColor;
    button.cornerRadius = 4;
    [button setTitle:@"退出账号" forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:17];
    [button setTitleColor:kWhiteColor forState:UIControlStateNormal];
    [button addTarget:self action:@selector(logoutAction) forControlEvents:UIControlEventTouchUpInside];
    [footerView addSubview:button];
    return footerView;
}

- (void)logoutAction{
    [EJSUserModel logout];
    [self leftBarButtonAction:nil];
}


@end
